package com.cw.DesignModel23.Structural.CompositePattern.Composite1;

/**
 * 书籍类
 *      重写了 CatalogComponent 的 getName / getPrice / printf 方法
 *      如果调用其余方法 , 会抛出异常
 */
public class Book extends CatalogComponent {
    /**
     * 书籍名称
     */
    private String name;

    /**
     * 书籍价格
     */
    private double price;

    public Book(String name, double price) {
        this.name = name;
        this.price = price;
    }

    @Override
    public String getName(CatalogComponent catalogComponent) {
        return this.name;
    }

    @Override
    public double getPrice(CatalogComponent catalogComponent) {
        return this.price;
    }

    @Override
    public void printf() {
        System.out.println("Book : name = " + name + " , price = " + price);
    }
}

